package cn.hchaojie.boot.aspect;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@ControllerAdvice
public class DefaultExeptionHandler {
	private Logger logger = LoggerFactory.getLogger(DefaultExeptionHandler.class);
	
	
	/** 处理文件上传的错 */
	@ExceptionHandler(MaxUploadSizeExceededException.class)
	@ResponseBody
	public String handleFileUploadException(MaxUploadSizeExceededException e) {
		// 将错误记录文件
		logger.error("文件上传出错", e);
		
		return "error";
	}
	
	/**
	 * 处理其它异常
	 * 
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public String handleGeneralException(Exception e) {
		logger.error("未知的服务器异常", e);
		
		return "/error/500";
	}
}
